package com.example.tests;


import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.util.Set;

import org.testng.annotations.Test;

public class ContactCreationTests extends TestBase{

	@Test
	public void testValidContactCanBeCreated() throws Exception {
		ContactObject validContact = new ContactObject()
					.setFirstname("2312")
					.setLastname("123123s")
					.setAddress("dasdas")
					.setHome("dasd")
					.setMobile("sdasd")
					.setWork("asdasd")
					.setEmail("asdas")
					.setEmail2("asd@.eg")
					.setBday("18")
					.setBmonth("October")
					.setByear("1231")
					.setNewgroup("sdfsdf")
					.setAddress2("asdasd")
					.setPhone2("asdasd");
		Set <ContactObject> oldList= app.getContactHelper().getContacts();
		app.getContactHelper().createContact(validContact);
		Set <ContactObject> newList= app.getContactHelper().getContacts();
		verifyContactAdded(oldList, validContact, newList);
	}
	
	private void verifyContactAdded(Set<ContactObject> oldList,
			ContactObject validContact, Set<ContactObject> newList) {
		assertThat(newList.size(), equalTo(oldList.size() + 1));
		validContact.setId("$$$");
		oldList.add(validContact);
		validContact.setId(null);
		assertThat(newList, equalTo(oldList));

	}
	
	@Test
	public void testEmptyContactCanBeCreated() throws Exception {
		ContactObject emptyContact = new ContactObject()
				.setFirstname("")
				.setLastname("")
				.setAddress("")
				.setHome("")
				.setMobile("")
				.setWork("")
				.setEmail("")
				.setEmail2("")
				.setBday("18")
				.setBmonth("October")
				.setByear("1231")
				.setNewgroup("")
				.setAddress2("")
				.setPhone2("asdasd");
		app.getContactHelper().createContact(emptyContact);
	}
	
}